<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人和人律师事务所管理系统v1.0-律师提成发票管理页面</title>

<!-- 控件布局方式，是否允许浮动 -->
<style type="text/css" media="all">
.allow-float {
	clear: none !important;
}  /* 允许该元素浮动 */
.stop-float {
	clear: both !important;
}  /* 阻止该元素浮动 */
.float-left {
	float: left;
	padding-left: 10px
} /*浮动到左边*/
</style>
<!-- 引入修改发票信息JS代码
<script type="text/javascript" src="js/lawyerRoyaltyInvoice.js"></script>
-->
<script type="text/javascript">
Ext.onReady(function(){
		var grid;

	//查询框
	var searchRoyInvoicePan=new Ext.form.FormPanel({
			title:'发票查询',
			labelAlign:'right',
			labelSeparator :'：',//分隔符
			labelWidth : 70,//标签宽度
			bodyStyle:'padding:5',//表单边距
			frame : true,
			collapsible: true,
			height:100,
			width:window.screen.width-220,
			applyTo :'searchInvoiceWin',

			items:[
				new Ext.form.TextField({
					fieldLabel : '承办律师',
					id : 'undertakeLawyer2',
					name : 'undertakeLawyer',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.TextField({
					fieldLabel : '合同号',
					id : 'contractId',
					name : 'contractId',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.Button({
					text : '开始查询',
					cls:'float-left',//向左浮动
					handler : submitMsg
				})
			]
	})



		//查询处理函数
	function submitMsg(){
		//获得查询条件
		var undertakeLawyer=Ext.getCmp("undertakeLawyer2").getValue();
		var contractId=Ext.getCmp("contractId").getValue();
		//判断是否输入了年份
		if(undertakeLawyer==""&&contractId=="")
		{
		Ext.Msg.alert('信息', '请输入查询条件再提交!');
		return;
		}
		 store = new Ext.data.JsonStore({
	url:"SearchInvoiceInfo.jsj?undertakeLawyer="+undertakeLawyer+"&contractId="+contractId,
	totalProperty: 'totalCount',
    root: 'result',
	fields:["invoicenumber","invoicetime","contractnumber","undertakelawyer","invoicemoney","invoiceperson","invoiceremark"]
});
		store.reload({
			params:{
				start:0,
				limit:5
				}
			});
		var colModel = new Ext.grid.ColumnModel([//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "发票编号",width: 200,  dataIndex: 'invoicenumber', sortable: true},
				{header: "发票开出时间", width: 200,dataIndex: 'invoicetime', sortable: true},
				{header: "合同编号",width: 200, dataIndex: 'contractnumber', sortable: true},
				{header: "承担律师",width: 300, dataIndex: 'undertakelawyer', sortable: true},
				{header: "开出金额",width: 300, dataIndex: 'invoicemoney', sortable: true},
				{header: "经手人",width: 300, dataIndex: 'invoiceperson', sortable: true},
				{header: "备注",width: 300, dataIndex: 'invoiceremark', sortable: true}
				]);
				pagebar.bind(store);
				grid.reconfigure(store,colModel);
		grid.getView().refresh(true);
	}


	 //存储器
	var store = new Ext.data.JsonStore({
	url:"InvoiceInfoRequest.jsj",
	totalProperty: 'totalCount',
	root: 'result',
	fields:["invoicenumber","invoicetime","contractnumber","undertakelawyer","invoicemoney","invoiceperson","invoiceremark"]
});
		store.load({
			params:{
				start:0,
				limit:5
				}
			});

	//获得用户权限
		var buttonDisabled=true;
	<%
	if((java.lang.Integer)session.getAttribute("popedomLevel")==1){
		%>
		buttonDisabled=false;
	<%
	}
	%>

		//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '发票详细信息'},
			'-',
			{
			text:'增加一条发票信息',
			iconCls:'add',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			addInvoiceInfo();
			}
			},
			'-',
			{
			text:'修改',
			iconCls:'option',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			modifyRoyaltyInvoiceFun();
			}
			}
		]);


 		//修改律师提成发票面板
    	 var modifyRoyaltyInvoicePanel;
     	//修改律师提成发票窗口
     	 var modifyRoyaltyInvoiceWin;
     	 //修改律师提成发票记录
     	  function modifyRoyaltyInvoiceFun(){
		 //获取要修改的一条记录
       	 var record=grid.getSelectionModel().getSelected();
       	//如果用户没有选择
       	if(!record){
       		Ext.MessageBox.alert('修改操作','请选择要修改的一项！');
       	   }else{
       		//修改律师提成发票窗口
       		modifyRoyaltyInvoiceWin=new Ext.Window({
       			layout:'fit',
       			width:500,
       			height:250,
       			closeAction:'hide',
				plain:true,
				title:'修改律师提成发票窗口',
				items:modifyRoyaltyInvoicePanel
       		});
       	     //显示窗口
       		modifyRoyaltyInvoiceWin.show();
       		//加载原数据
       		 Ext.getCmp("minvoiceid").setValue(record.get("invoicenumber"));
       		 Ext.getCmp("minvoicetime").setValue(record.get("invoicetime"));
       		 Ext.getCmp("mroyaltycontract").setValue(record.get("contractnumber"));
       		 Ext.getCmp("minvoiceperson").setValue(record.get("invoiceperson"));
       		 Ext.getCmp("minvoiceamount").setValue(record.get("invoicemoney"));
       	     Ext.getCmp("minvoiceremark").setValue(record.get("invoiceremark"));

       	}
       }

       //修改律师提成发票面板
       modifyRoyaltyInvoicePanel=new Ext.form.FormPanel({
        labelAlign:'right',
        buttonAlign:'center',
       	collapsible:true,
       	labelwidth:100,
       	frame:true,
       	bodyStyle : 'padding:5px 5px 0',
        waitMsgTarget : true,

        defaults : {
            width : 250
        },
        defaultType : 'textfield',
        items : [
         {
            fieldLabel : '发票编号',
            itemCls:'float-left',//向左浮动
		    clearCls:'allow-float',//允许浮动
            name :'minvoiceid',
            id :'minvoiceid',
            allowBlank :false
        },
        {
            fieldLabel : '发票开出时间',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'minvoicetime',
            id :'minvoicetime',
            allowBlank :false
        },
        {
            fieldLabel : '合同号',
            itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
            name :'mroyaltycontract',
            id :'mroyaltycontract',
            allowBlank :false
        },
        {
            fieldLabel :'金额',
			id :'minvoiceamount',
			name :'minvoiceamount',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        },
        {
            fieldLabel :'经手人',
			id :'minvoiceperson',
			name :'minvoiceperson',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        },
        {
            fieldLabel :'备注',
			id :'minvoiceremark',
			name :'minvoiceremark',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			allowBlank :false
        }
        ],
        buttons : [ {
            text : '保存',
            disabled : false,
            handler : function() {
                if (modifyRoyaltyInvoicePanel.form.isValid()) {
                    modifyRoyaltyInvoicePanel.form.submit( {
                        url : 'ModifyRoyaltyInvoiceInfo.jsj',
                        success : function(from, action) {
                        Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyRoyaltyInvoiceWin.hide();
                        },
                        failure : function(form, action) {
                           Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyRoyaltyInvoiceWin.hide();
                        },
                        waitMsg : '正在保存数据，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        }, {
            text : '取消',
            handler : function() {
                modifyRoyaltyInvoiceWin.hide();
            }
        }]
       })




        //增加发票信息窗口
		var addInvoiceWindow;
		//增加发票信息面板
		var addInvoiceForm;
		//增加一条发票信息处理函数
function addInvoiceInfo(){
		 addInvoiceWindow=new Ext.Window({
			title:'增加一条发票信息记录',
			width:550,
			height:300,
			layout:'fit',
			closeAction:'hide',
			resizable:false,
			items:addInvoiceForm
		});
		addInvoiceWindow.show();
	}
	//增加银行帐面板
	 addInvoiceForm=new Ext.FormPanel({
	 		labelAlign:'right',
	 		buttonAlign:'center',
	 		frame:true,
	 		labelWidth:180,
	 		defaults:{
	 		width:180,
	 		},
		items:[
		{
			xtype:'datefield',
			fieldLabel:'时间',
			format:'Y-m-d',
			name:'invoiceAccTime',
			allowBlank:false
		},
		{
			xtype:'textfield',
			fieldLabel:'发票编号',
			name:'invoiceId',
			allowBlank:false
		},

			new  Ext.form.ComboBox({
			fieldLabel:'请选择合同编号',
			store:new Ext.data.JsonStore({
			url:'ContractNumbersRequest.jsj',
			totalProperty:'totalCount',
			root:'result',
			fields:["contractid"]
			}),
			valueField:'contractid',
			displayField:'contractid',
			forceSelection:true,
			emptyText:'请选择合同编号',
			hiddenName:'contract',
			editable:true,
			triggerAction:'all',
			id:'acontractId',
			name:'acontractId'
			}),
		{
			xtype:'textfield',
			fieldLabel:'开出金额',
			name:'Payout',
			allowBlank:false
		},
		{
			xtype:'textfield',
			fieldLabel:'经手人',
			name:'invoicePer',
			allowBlank:false
		},
		{
			xtype:'textarea',
			fieldLabel:'备注',
			height:100,
			name:'invoiceBrief',
			allowBlank:false
		}
		],
		buttons:[{
		text:'确认',
		handler:function(){
			if(addInvoiceForm.form.isValid()){
				addInvoiceForm.form.submit({
				url:'AddInvoiceInfo.jsj',
				success:function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addInvoiceWindow.hide();
				},
				failure: function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addInvoiceWindow.hide();
				},
				waitMsg:'正在保存数据，稍后...'
				});
			} else {
				Ext.Msg.alert('信息', '请填写完成再提交!');
			}
		}
		},{
		 text:'取消',
		 handler:function(){
		 	addInvoiceWindow.hide();
		 }
		}]
	});





		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});
		//创建选择模式对象
	var cb = new Ext.grid.CheckboxSelectionModel()
	//创建Grid表格组件
	 grid = new Ext.grid.GridPanel({
			renderTo : 'invoice-detail-info',
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			trackMouseOver:true, //鼠标特效
			loadMask: true,    //是否显示正在加载
			store : store,
			height : 320,
			width : window.screen.width-220,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "发票编号",width: 200,  dataIndex: 'invoicenumber', sortable: true},
				{header: "发票开出时间", width: 200,dataIndex: 'invoicetime', sortable: true},
				{header: "合同编号",width: 200, dataIndex: 'contractnumber', sortable: true},
				{header: "承担律师",width: 300, dataIndex: 'undertakelawyer', sortable: true},
				{header: "开出金额",width: 300, dataIndex: 'invoicemoney', sortable: true},
				{header: "经手人",width: 300, dataIndex: 'invoiceperson', sortable: true},
				{header: "备注",width: 300, dataIndex: 'invoiceremark', sortable: true}
				]
		});
})

</script>
</head>
<body>
<table>
	<tr>
		<td>
		<div id='searchInvoiceWin' style="margin: 8px 8px 4px 8px"></div>
		</td>
	</tr>
</table>
<div id='invoice-detail-info' style="margin: 4px 8px 8px 8px"></div>

</body>
</html>